
import { type PaginationProps } from "@pureadmin/table";
import { GetPortraitIndexModelBaseData, AddOrUpdataPortraitIndexSystem, GetPortraitIndexSystemList, GetPortraitIndexSystemDetail } from "@/api/stu/bankBigData";
import { useRoute } from "vue-router";
import { ElMessage } from "element-plus";
import { ref, reactive, watch, onMounted } from "vue";
export function useCreditReport() {
  const route = useRoute();
  const dataList = ref<any>([]); //接口原数据
  const tableList = ref()
  const selectList = ref() //选择器数据
  const addVisible = ref<boolean>(false); //新建弹窗
  //八个模块的数据库
  const title = ref()
  const selectType = ref([])
  const personalStabilityList = ref()
  const gameAddictionList = ref()
  const performanceCapabilityList = ref()
  const maliciousOverdraftList = ref()
  const fundingRequirementsList = ref()
  const socialActivityList = ref()
  const onlineShoppingList = ref()
  const spendingPowerList = ref()
  //定义控制显示的内容 主要是方便封装方法
  const variables = reactive({
    PersonalStability: false,
    GameAddiction: false,
    PerformanceCapability: false,
    MaliciousOverdraft: false,
    FundingRequirements: false,
    SocialActivity: false,
    OnlineShopping: false,
    SpendingPower: false,
    // 其他变量...
  });
  //定义的ref方便获取对应的子组件数据
  const PersonalStability = ref(null)
  const GameAddiction = ref(null)
  const PerformanceCapability = ref(null)
  const MaliciousOverdraft = ref(null)
  const FundingRequirements = ref(null)
  const SocialActivity = ref(null)
  const OnlineShopping = ref(null)
  const SpendingPower = ref(null)


  const ShowReport = ref<string>();
  const loading = ref<boolean>(false);
  const pagination = reactive<PaginationProps>({
    total: 0,
    pageSize: 30,
    currentPage: 1,
    pageSizes: [5, 10, 30],
    background: true
  });
  const columns: TableColumnList = [
    {
      label: "序号",
      type: "index",
      width: 120
    },
    {
      label: "指数体系名称",
      prop: "userModelName",
      minWidth: 200
    },
    {
      label: "操作",
      fixed: "right",
      width: 180,
      slot: "operation"
    }
  ];

  //查看已经创建的模型
  const showVisible = ref<boolean>(false); //查看弹窗
  const showTitle = ref() //显示标题
  const showSelectModel = ref() //显示选中的模块
  const showData = ref()
  const BtnLoading = ref<boolean>(false)
  function OUTBtnLoding() {
    setTimeout(() => {
      BtnLoading.value = false
    }, 1000)
  }
  async function getAddList() {
    const respone = await GetPortraitIndexModelBaseData();
    if (respone.success) {
      dataList.value = respone?.data
      selectList.value = respone?.data.map(item => {
        return {
          name: item.modelName,
          value: item.modelCode,
        }
      });
      const variableMappings = {
        'PersonalStability': personalStabilityList,
        'GameAddiction': gameAddictionList,
        'PerformanceCapability': performanceCapabilityList,
        'MaliciousOverdraft': maliciousOverdraftList,
        'FundingRequirements': fundingRequirementsList,
        'SocialActivity': socialActivityList,
        'OnlineShopping': onlineShoppingList,
        'SpendingPower': spendingPowerList
      };

      for (const modelCode in variableMappings) {
        variableMappings[modelCode].value = respone?.data.filter(item => item.modelCode === modelCode);
      }
    } else {
      ElMessage.error(respone.msg);
    }
  }

  async function getList() {
    const data = {
      taskId: route.query.taskId,
      planId: route.query.planId,
      pageIndex: pagination.currentPage,
      pageCount: pagination.pageSize,
    };
    const respone = await GetPortraitIndexSystemList(data);
    if (respone.success) {
      respone.data?.items.forEach(item => {
        item.createTime = item.createTime.substring(0, 10)
      })
      pagination.total = respone.data.totalCount;
      tableList.value = respone.data.items;
    } else {
      ElMessage.error(respone.msg);
    }
  }

  onMounted(() => {
    getAddList()
    getList()
  })

  //暂时还没有优化代码 八个方法都一样 只是绑定的ref不同
  //l类似这样const handleData = (modelCode, refValue) => {
  // const object2 = {
  //   "modelCode": modelCode,
  //   "modelParamValues": []
  // };
  // refValue.value.tableList.forEach
  async function SubmitVisible() {
    if (title.value == '' || title.value == undefined) {
      ElMessage.warning('体系名称不能为空！')
      return
    }
    if (selectType.value.length == 0) {
      ElMessage.warning('请选择指数模型类！')
      return
    }
    if (selectType.value.length !== 8) {
      ElMessage.warning('指数模型类需要全选！')
      return
    }
    //先找出已经打开的子组件
    const resultParams = {
      taskId: route.query.taskId,
      planId: route.query.planId,
      portraitIndexSystemId: "",
      userModelName: title.value,
      requestParams: [],
    }
    const truePropertiesArray = Object.keys(variables).filter(property => variables[property] === true);
    let sum = 0
    //处理提交给接口的数据
    truePropertiesArray.forEach(item => {
      //个人指数模型
      if (item == 'PersonalStability') {
        var object2 = {
          "modelCode": "PersonalStability",
          "modelParamValues": []
        };
        PersonalStability.value.tableList.forEach(item => {
          sum += Number(item.indicatorWeight)
          var extractedData = {
            "apiFieldInfoId": item.apiFieldInfoId,
            "dataField": item.dataField,
            "evaluationCriterionList": [],
            "indicatorWeight": item.indicatorWeight,
          };
          //dataSetType 1是从大到小  2是从小到大  3是单选 4是多选
          if (item.dataSetType == 1) {
            const selectList = item.column.map(item => item.value).join(',');
            const evaluationCriterionList = [
              { evaluationCriterion: 3 },
              { evaluationCriterion: 5 },
              { evaluationCriterion: 8 },
              { evaluationCriterion: 10 }
            ];
            selectList.split(",").slice(0, 4).forEach((value, index) => {
              evaluationCriterionList[index].leftNumericalValue = parseInt(value);
              evaluationCriterionList[index].rightNumericalValue = parseInt(selectList.split(",")[index + 1]);
            });
            extractedData.evaluationCriterionList.push(...evaluationCriterionList);
          }
          if (item.dataSetType == 2) {
            const selectList = item.column.map(item => item.value).join(',');
            const evaluationCriterionList = [
              { evaluationCriterion: 3 },
              { evaluationCriterion: 5 },
              { evaluationCriterion: 8 },
              { evaluationCriterion: 10 }
            ];
            selectList.split(",").slice(0, 4).forEach((value, index) => {
              evaluationCriterionList[index].leftNumericalValue = parseInt(value);
              evaluationCriterionList[index].rightNumericalValue = parseInt(selectList.split(",")[index + 1]);
            });
            extractedData.evaluationCriterionList.push(...evaluationCriterionList);
          }
          if (item.dataSetType == 3) {
            let arr = item.column.map(item => item.value);
            const evaluationCriterionList = [
              { evaluationCriterion: 3, textTypeValue: arr[0] },
              { evaluationCriterion: 5, textTypeValue: arr[1] },
              { evaluationCriterion: 8, textTypeValue: arr[2] },
              { evaluationCriterion: 10, textTypeValue: arr[3] }
            ];
            extractedData.evaluationCriterionList.push(...evaluationCriterionList);
          }
          if (item.dataSetType == 4) {
            let arr = item.column.map(item => item.value.join('|'));
            const evaluationCriterionList = [
              { evaluationCriterion: 3, textTypeValue: arr[0] },
              { evaluationCriterion: 5, textTypeValue: arr[1] },
              { evaluationCriterion: 8, textTypeValue: arr[2] },
              { evaluationCriterion: 10, textTypeValue: arr[3] }
            ];
            extractedData.evaluationCriterionList.push(...evaluationCriterionList);
          }
          object2.modelParamValues.push(extractedData)
        })
        resultParams.requestParams.push(object2)
      }
      //游戏沉迷模型
      if (item == 'GameAddiction') {
        var object2 = {
          "modelCode": "GameAddiction",
          "modelParamValues": []
        };
        GameAddiction.value.tableList.forEach(item => {
          sum += Number(item.indicatorWeight)
          var extractedData = {
            "apiFieldInfoId": item.apiFieldInfoId,
            "dataField": item.dataField,
            "evaluationCriterionList": [],
            "indicatorWeight": item.indicatorWeight,
          };
          if (item.dataSetType == 1) {
            const selectList = item.column.map(item => item.value).join(',');

            const evaluationCriterionList = [
              { evaluationCriterion: 3 },
              { evaluationCriterion: 5 },
              { evaluationCriterion: 8 },
              { evaluationCriterion: 10 }
            ];

            selectList.split(",").slice(0, 4).forEach((value, index) => {
              evaluationCriterionList[index].leftNumericalValue = parseInt(value);
              evaluationCriterionList[index].rightNumericalValue = parseInt(selectList.split(",")[index + 1]);
            });

            extractedData.evaluationCriterionList.push(...evaluationCriterionList);
          }
          if (item.dataSetType == 2) {
            const selectList = item.column.map(item => item.value).join(',');

            const evaluationCriterionList = [
              { evaluationCriterion: 3 },
              { evaluationCriterion: 5 },
              { evaluationCriterion: 8 },
              { evaluationCriterion: 10 }
            ];

            selectList.split(",").slice(0, 4).forEach((value, index) => {
              evaluationCriterionList[index].leftNumericalValue = parseInt(value);
              evaluationCriterionList[index].rightNumericalValue = parseInt(selectList.split(",")[index + 1]);
            });

            extractedData.evaluationCriterionList.push(...evaluationCriterionList);
          }
          if (item.dataSetType == 3) {
            let arr = item.column.map(item => item.value);
            const evaluationCriterionList = [
              { evaluationCriterion: 3, textTypeValue: arr[0] },
              { evaluationCriterion: 5, textTypeValue: arr[1] },
              { evaluationCriterion: 8, textTypeValue: arr[2] },
              { evaluationCriterion: 10, textTypeValue: arr[3] }
            ];
            extractedData.evaluationCriterionList.push(...evaluationCriterionList);
          }
          if (item.dataSetType == 4) {
            let arr = item.column.map(item => item.value.join('|'));
            const evaluationCriterionList = [
              { evaluationCriterion: 3, textTypeValue: arr[0] },
              { evaluationCriterion: 5, textTypeValue: arr[1] },
              { evaluationCriterion: 8, textTypeValue: arr[2] },
              { evaluationCriterion: 10, textTypeValue: arr[3] }
            ];
            extractedData.evaluationCriterionList.push(...evaluationCriterionList);
          }
          object2.modelParamValues.push(extractedData)
        })
        resultParams.requestParams.push(object2)
      }
      //履约能力模型
      if (item == 'PerformanceCapability') {
        var object2 = {
          "modelCode": "PerformanceCapability",
          "modelParamValues": []
        };
        PerformanceCapability.value.tableList.forEach(item => {
          sum += Number(item.indicatorWeight)
          var extractedData = {
            "apiFieldInfoId": item.apiFieldInfoId,
            "dataField": item.dataField,
            "evaluationCriterionList": [],
            "indicatorWeight": item.indicatorWeight,
          };
          if (item.dataSetType == 1) {
            const selectList = item.column.map(item => item.value).join(',');
            const evaluationCriterionList = [
              { evaluationCriterion: 3 },
              { evaluationCriterion: 5 },
              { evaluationCriterion: 8 },
              { evaluationCriterion: 10 }
            ];

            selectList.split(",").slice(0, 4).forEach((value, index) => {
              evaluationCriterionList[index].leftNumericalValue = parseInt(value);
              evaluationCriterionList[index].rightNumericalValue = parseInt(selectList.split(",")[index + 1]);
            });
            extractedData.evaluationCriterionList.push(...evaluationCriterionList);
          }
          if (item.dataSetType == 2) {
            const selectList = item.column.map(item => item.value).join(',');

            const evaluationCriterionList = [
              { evaluationCriterion: 3 },
              { evaluationCriterion: 5 },
              { evaluationCriterion: 8 },
              { evaluationCriterion: 10 }
            ];
            selectList.split(",").slice(0, 4).forEach((value, index) => {
              evaluationCriterionList[index].leftNumericalValue = parseInt(value);
              evaluationCriterionList[index].rightNumericalValue = parseInt(selectList.split(",")[index + 1]);
            });
            extractedData.evaluationCriterionList.push(...evaluationCriterionList);
          }
          if (item.dataSetType == 3) {
            let arr = item.column.map(item => item.value);
            const evaluationCriterionList = [
              { evaluationCriterion: 3, textTypeValue: arr[0] },
              { evaluationCriterion: 5, textTypeValue: arr[1] },
              { evaluationCriterion: 8, textTypeValue: arr[2] },
              { evaluationCriterion: 10, textTypeValue: arr[3] }
            ];
            extractedData.evaluationCriterionList.push(...evaluationCriterionList);
          }
          if (item.dataSetType == 4) {
            let arr = item.column.map(item => item.value.join('|'));
            const evaluationCriterionList = [
              { evaluationCriterion: 3, textTypeValue: arr[0] },
              { evaluationCriterion: 5, textTypeValue: arr[1] },
              { evaluationCriterion: 8, textTypeValue: arr[2] },
              { evaluationCriterion: 10, textTypeValue: arr[3] }
            ];
            extractedData.evaluationCriterionList.push(...evaluationCriterionList);
          }
          object2.modelParamValues.push(extractedData)
        })
        resultParams.requestParams.push(object2)
      }
      //恶意透支模型
      if (item == 'MaliciousOverdraft') {
        var object2 = {
          "modelCode": "MaliciousOverdraft",
          "modelParamValues": []
        };
        MaliciousOverdraft.value.tableList.forEach(item => {
          sum += Number(item.indicatorWeight)
          var extractedData = {
            "apiFieldInfoId": item.apiFieldInfoId,
            "dataField": item.dataField,
            "evaluationCriterionList": [],
            "indicatorWeight": item.indicatorWeight,
          };
          if (item.dataSetType == 1) {
            const selectList = item.column.map(item => item.value).join(',');
            const evaluationCriterionList = [
              { evaluationCriterion: 3 },
              { evaluationCriterion: 5 },
              { evaluationCriterion: 8 },
              { evaluationCriterion: 10 }
            ];

            selectList.split(",").slice(0, 4).forEach((value, index) => {
              evaluationCriterionList[index].leftNumericalValue = parseInt(value);
              evaluationCriterionList[index].rightNumericalValue = parseInt(selectList.split(",")[index + 1]);
            });
            extractedData.evaluationCriterionList.push(...evaluationCriterionList);
          }
          if (item.dataSetType == 2) {
            const selectList = item.column.map(item => item.value).join(',');

            const evaluationCriterionList = [
              { evaluationCriterion: 3 },
              { evaluationCriterion: 5 },
              { evaluationCriterion: 8 },
              { evaluationCriterion: 10 }
            ];
            selectList.split(",").slice(0, 4).forEach((value, index) => {
              evaluationCriterionList[index].leftNumericalValue = parseInt(value);
              evaluationCriterionList[index].rightNumericalValue = parseInt(selectList.split(",")[index + 1]);
            });
            extractedData.evaluationCriterionList.push(...evaluationCriterionList);
          }
          if (item.dataSetType == 3) {
            let arr = item.column.map(item => item.value);
            const evaluationCriterionList = [
              { evaluationCriterion: 3, textTypeValue: arr[0] },
              { evaluationCriterion: 5, textTypeValue: arr[1] },
              { evaluationCriterion: 8, textTypeValue: arr[2] },
              { evaluationCriterion: 10, textTypeValue: arr[3] }
            ];
            extractedData.evaluationCriterionList.push(...evaluationCriterionList);
          }
          if (item.dataSetType == 4) {
            let arr = item.column.map(item => item.value.join('|'));
            const evaluationCriterionList = [
              { evaluationCriterion: 3, textTypeValue: arr[0] },
              { evaluationCriterion: 5, textTypeValue: arr[1] },
              { evaluationCriterion: 8, textTypeValue: arr[2] },
              { evaluationCriterion: 10, textTypeValue: arr[3] }
            ];
            extractedData.evaluationCriterionList.push(...evaluationCriterionList);
          }
          object2.modelParamValues.push(extractedData)
        })
        resultParams.requestParams.push(object2)
      }
      //资金需求模型
      if (item == 'FundingRequirements') {
        var object2 = {
          "modelCode": "FundingRequirements",
          "modelParamValues": []
        };
        FundingRequirements.value.tableList.forEach(item => {
          sum += Number(item.indicatorWeight)
          var extractedData = {
            "apiFieldInfoId": item.apiFieldInfoId,
            "dataField": item.dataField,
            "evaluationCriterionList": [],
            "indicatorWeight": item.indicatorWeight,
          };
          if (item.dataSetType == 1) {
            const selectList = item.column.map(item => item.value).join(',');
            const evaluationCriterionList = [
              { evaluationCriterion: 3 },
              { evaluationCriterion: 5 },
              { evaluationCriterion: 8 },
              { evaluationCriterion: 10 }
            ];

            selectList.split(",").slice(0, 4).forEach((value, index) => {
              evaluationCriterionList[index].leftNumericalValue = parseInt(value);
              evaluationCriterionList[index].rightNumericalValue = parseInt(selectList.split(",")[index + 1]);
            });
            extractedData.evaluationCriterionList.push(...evaluationCriterionList);
          }
          if (item.dataSetType == 2) {
            const selectList = item.column.map(item => item.value).join(',');

            const evaluationCriterionList = [
              { evaluationCriterion: 3 },
              { evaluationCriterion: 5 },
              { evaluationCriterion: 8 },
              { evaluationCriterion: 10 }
            ];
            selectList.split(",").slice(0, 4).forEach((value, index) => {
              evaluationCriterionList[index].leftNumericalValue = parseInt(value);
              evaluationCriterionList[index].rightNumericalValue = parseInt(selectList.split(",")[index + 1]);
            });
            extractedData.evaluationCriterionList.push(...evaluationCriterionList);
          }
          if (item.dataSetType == 3) {
            let arr = item.column.map(item => item.value);
            const evaluationCriterionList = [
              { evaluationCriterion: 3, textTypeValue: arr[0] },
              { evaluationCriterion: 5, textTypeValue: arr[1] },
              { evaluationCriterion: 8, textTypeValue: arr[2] },
              { evaluationCriterion: 10, textTypeValue: arr[3] }
            ];
            extractedData.evaluationCriterionList.push(...evaluationCriterionList);
          }
          if (item.dataSetType == 4) {
            let arr = item.column.map(item => item.value.join('|'));
            const evaluationCriterionList = [
              { evaluationCriterion: 3, textTypeValue: arr[0] },
              { evaluationCriterion: 5, textTypeValue: arr[1] },
              { evaluationCriterion: 8, textTypeValue: arr[2] },
              { evaluationCriterion: 10, textTypeValue: arr[3] }
            ];
            extractedData.evaluationCriterionList.push(...evaluationCriterionList);
          }
          object2.modelParamValues.push(extractedData)
        })
        resultParams.requestParams.push(object2)
      }
      //社交活跃度模型
      if (item == 'SocialActivity') {
        var object2 = {
          "modelCode": "SocialActivity",
          "modelParamValues": []
        };
        SocialActivity.value.tableList.forEach(item => {
          sum += Number(item.indicatorWeight)
          var extractedData = {
            "apiFieldInfoId": item.apiFieldInfoId,
            "dataField": item.dataField,
            "evaluationCriterionList": [],
            "indicatorWeight": item.indicatorWeight,
          };
          if (item.dataSetType == 1) {
            const selectList = item.column.map(item => item.value).join(',');
            const evaluationCriterionList = [
              { evaluationCriterion: 3 },
              { evaluationCriterion: 5 },
              { evaluationCriterion: 8 },
              { evaluationCriterion: 10 }
            ];

            selectList.split(",").slice(0, 4).forEach((value, index) => {
              evaluationCriterionList[index].leftNumericalValue = parseInt(value);
              evaluationCriterionList[index].rightNumericalValue = parseInt(selectList.split(",")[index + 1]);
            });
            extractedData.evaluationCriterionList.push(...evaluationCriterionList);
          }
          if (item.dataSetType == 2) {
            const selectList = item.column.map(item => item.value).join(',');

            const evaluationCriterionList = [
              { evaluationCriterion: 3 },
              { evaluationCriterion: 5 },
              { evaluationCriterion: 8 },
              { evaluationCriterion: 10 }
            ];
            selectList.split(",").slice(0, 4).forEach((value, index) => {
              evaluationCriterionList[index].leftNumericalValue = parseInt(value);
              evaluationCriterionList[index].rightNumericalValue = parseInt(selectList.split(",")[index + 1]);
            });
            extractedData.evaluationCriterionList.push(...evaluationCriterionList);
          }
          if (item.dataSetType == 3) {
            let arr = item.column.map(item => item.value);
            const evaluationCriterionList = [
              { evaluationCriterion: 3, textTypeValue: arr[0] },
              { evaluationCriterion: 5, textTypeValue: arr[1] },
              { evaluationCriterion: 8, textTypeValue: arr[2] },
              { evaluationCriterion: 10, textTypeValue: arr[3] }
            ];
            extractedData.evaluationCriterionList.push(...evaluationCriterionList);
          }
          if (item.dataSetType == 4) {
            let arr = item.column.map(item => item.value.join('|'));
            const evaluationCriterionList = [
              { evaluationCriterion: 3, textTypeValue: arr[0] },
              { evaluationCriterion: 5, textTypeValue: arr[1] },
              { evaluationCriterion: 8, textTypeValue: arr[2] },
              { evaluationCriterion: 10, textTypeValue: arr[3] }
            ];
            extractedData.evaluationCriterionList.push(...evaluationCriterionList);
          }
          object2.modelParamValues.push(extractedData)
        })
        resultParams.requestParams.push(object2)
      }
      //网购倾向模型
      if (item == 'OnlineShopping') {
        var object2 = {
          "modelCode": "OnlineShopping",
          "modelParamValues": []
        };
        OnlineShopping.value.tableList.forEach(item => {
          sum += Number(item.indicatorWeight)
          var extractedData = {
            "apiFieldInfoId": item.apiFieldInfoId,
            "dataField": item.dataField,
            "evaluationCriterionList": [],
            "indicatorWeight": item.indicatorWeight,
          };
          if (item.dataSetType == 1) {
            const selectList = item.column.map(item => item.value).join(',');
            const evaluationCriterionList = [
              { evaluationCriterion: 3 },
              { evaluationCriterion: 5 },
              { evaluationCriterion: 8 },
              { evaluationCriterion: 10 }
            ];

            selectList.split(",").slice(0, 4).forEach((value, index) => {
              evaluationCriterionList[index].leftNumericalValue = parseInt(value);
              evaluationCriterionList[index].rightNumericalValue = parseInt(selectList.split(",")[index + 1]);
            });
            extractedData.evaluationCriterionList.push(...evaluationCriterionList);
          }
          if (item.dataSetType == 2) {
            const selectList = item.column.map(item => item.value).join(',');

            const evaluationCriterionList = [
              { evaluationCriterion: 3 },
              { evaluationCriterion: 5 },
              { evaluationCriterion: 8 },
              { evaluationCriterion: 10 }
            ];
            selectList.split(",").slice(0, 4).forEach((value, index) => {
              evaluationCriterionList[index].leftNumericalValue = parseInt(value);
              evaluationCriterionList[index].rightNumericalValue = parseInt(selectList.split(",")[index + 1]);
            });
            extractedData.evaluationCriterionList.push(...evaluationCriterionList);
          }
          if (item.dataSetType == 3) {
            let arr = item.column.map(item => item.value);
            const evaluationCriterionList = [
              { evaluationCriterion: 3, textTypeValue: arr[0] },
              { evaluationCriterion: 5, textTypeValue: arr[1] },
              { evaluationCriterion: 8, textTypeValue: arr[2] },
              { evaluationCriterion: 10, textTypeValue: arr[3] }
            ];
            extractedData.evaluationCriterionList.push(...evaluationCriterionList);
          }
          if (item.dataSetType == 4) {
            let arr = item.column.map(item => item.value.join('|'));
            const evaluationCriterionList = [
              { evaluationCriterion: 3, textTypeValue: arr[0] },
              { evaluationCriterion: 5, textTypeValue: arr[1] },
              { evaluationCriterion: 8, textTypeValue: arr[2] },
              { evaluationCriterion: 10, textTypeValue: arr[3] }
            ];
            extractedData.evaluationCriterionList.push(...evaluationCriterionList);
          }
          object2.modelParamValues.push(extractedData)
        })
        resultParams.requestParams.push(object2)
      }
      //消费能力模型
      if (item == 'SpendingPower') {
        var object2 = {
          "modelCode": "SpendingPower",
          "modelParamValues": []
        };
        SpendingPower.value.tableList.forEach(item => {
          sum += Number(item.indicatorWeight)
          var extractedData = {
            "apiFieldInfoId": item.apiFieldInfoId,
            "dataField": item.dataField,
            "evaluationCriterionList": [],
            "indicatorWeight": item.indicatorWeight,
          };
          if (item.dataSetType == 1) {
            const selectList = item.column.map(item => item.value).join(',');
            const evaluationCriterionList = [
              { evaluationCriterion: 3 },
              { evaluationCriterion: 5 },
              { evaluationCriterion: 8 },
              { evaluationCriterion: 10 }
            ];

            selectList.split(",").slice(0, 4).forEach((value, index) => {
              evaluationCriterionList[index].leftNumericalValue = parseInt(value);
              evaluationCriterionList[index].rightNumericalValue = parseInt(selectList.split(",")[index + 1]);
            });
            extractedData.evaluationCriterionList.push(...evaluationCriterionList);
          }
          if (item.dataSetType == 2) {
            const selectList = item.column.map(item => item.value).join(',');

            const evaluationCriterionList = [
              { evaluationCriterion: 3 },
              { evaluationCriterion: 5 },
              { evaluationCriterion: 8 },
              { evaluationCriterion: 10 }
            ];
            selectList.split(",").slice(0, 4).forEach((value, index) => {
              evaluationCriterionList[index].leftNumericalValue = parseInt(value);
              evaluationCriterionList[index].rightNumericalValue = parseInt(selectList.split(",")[index + 1]);
            });
            extractedData.evaluationCriterionList.push(...evaluationCriterionList);
          }
          if (item.dataSetType == 3) {
            let arr = item.column.map(item => item.value);
            const evaluationCriterionList = [
              { evaluationCriterion: 3, textTypeValue: arr[0] },
              { evaluationCriterion: 5, textTypeValue: arr[1] },
              { evaluationCriterion: 8, textTypeValue: arr[2] },
              { evaluationCriterion: 10, textTypeValue: arr[3] }
            ];
            extractedData.evaluationCriterionList.push(...evaluationCriterionList);
          }
          if (item.dataSetType == 4) {
            let arr = item.column.map(item => item.value.join('|'));
            const evaluationCriterionList = [
              { evaluationCriterion: 3, textTypeValue: arr[0] },
              { evaluationCriterion: 5, textTypeValue: arr[1] },
              { evaluationCriterion: 8, textTypeValue: arr[2] },
              { evaluationCriterion: 10, textTypeValue: arr[3] }
            ];
            extractedData.evaluationCriterionList.push(...evaluationCriterionList);
          }
          object2.modelParamValues.push(extractedData)
        })
        resultParams.requestParams.push(object2)
      }
    })
    if (sum != 100 * truePropertiesArray.length) {
      ElMessage.warning('指标权重总和应为100%');
      return
    }
    const json = {
      userModelName: resultParams.userModelName,
      requesrParams: resultParams.requestParams,
    }
    resultParams.studentAnswer = JSON.stringify(json)
    BtnLoading.value = true;
    OUTBtnLoding()
    let res = await AddOrUpdataPortraitIndexSystem(resultParams)
    if (res.status == 200) {
      ElMessage.success(res.msg);
      addVisible.value = false
      selectType.value = []
      for (let variable in variables) {
        variables[variable] = false;
      }
      getList()
    } else {
      ElMessage.error(res.msg);
    }
  }

  function CloseVisible() {
    addVisible.value = false
    selectType.value = []
    title.value = ''
    for (let variable in variables) {
      variables[variable] = false;
    }
  }

  function handleSizeChange(val) {
    getList()
  }
  function handleCurrentChange(val) {
    getList()
  }
  watch(selectType, (newValue, oldValue) => {
    // 找到新添加的元素
    if (newValue.length > oldValue.length) {
      const addedItems = newValue.filter(item => !oldValue.includes(item));
      // 将新添加的元素传递给changeVariable函数
      addedItems.forEach(item => {
        variables[item] = true
      });
    } else {
      const deleteItems = oldValue.filter(item => !newValue.includes(item));
      // 将新添加的元素传递给changeVariable函数
      deleteItems.forEach(item => {
        variables[item] = false
      });
    }
  });

  async function CheckCreditReport(row) {
    console.log(row);
    const data = {
      taskId: route.query.taskId,
      planId: route.query.planId,
      detailId: row.portraitIndexSystemId
    };
    const respone = await GetPortraitIndexSystemDetail(data);
    if (respone.success) {
      showTitle.value = row.userModelName
      showSelectModel.value = selectList.value.map(item => { return item.value })
      showData.value = respone.data[0].modelInfos
      showVisible.value = true
    } else {
      ElMessage.error(respone.msg);
    }
  }

  function closeShowVisible() {
    showVisible.value = false
  }
  return {
    dataList,
    tableList,
    loading,
    pagination,
    columns,
    ShowReport,
    addVisible,
    title,
    selectList,
    selectType,
    variables,
    BtnLoading,
    personalStabilityList,
    gameAddictionList,
    performanceCapabilityList,
    maliciousOverdraftList,
    fundingRequirementsList,
    socialActivityList,
    onlineShoppingList,
    spendingPowerList,
    PersonalStability,
    GameAddiction,
    PerformanceCapability,
    MaliciousOverdraft,
    FundingRequirements,
    SocialActivity,
    OnlineShopping,
    SpendingPower,
    showVisible,
    showTitle,
    showSelectModel,
    showData,
    SubmitVisible,
    CloseVisible,
    handleSizeChange,
    handleCurrentChange,
    CheckCreditReport,
    closeShowVisible
  }
}
